const { DataTypes } = require('sequelize');
const sequelize = require('../index');

const Work = sequelize.define('db_works', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment: '主键，自动递增'
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'db_users',
            key: 'id',
        },
    },
    job_title: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true,
        comment: '岗位名称'
    },
    popularity_rating: {
        type: DataTypes.DECIMAL(2, 1),
        allowNull: false,
        defaultValue: 0.0,
        validate: {
            min: 0,
            max: 5
        },
        comment: '热门评分，最高五颗星，允许一位小数'
    },
    job_description: {
        type: DataTypes.TEXT,
        comment: '岗位描述'
    },
    job_requirements: {
        type: DataTypes.TEXT,
        comment: '岗位要求'
    },
    salary: {
        type: DataTypes.STRING,
        comment: '薪资待遇'
    },
    benefits: {
        type: DataTypes.TEXT,
        comment: '福利待遇'
    },
    remote: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
        comment: '是否远程办公'
    },
    duration: {
        type: DataTypes.STRING,
        comment: '工作期限，例如长期、1年合同等'
    },
    min_salary: {
        type: DataTypes.DECIMAL(10, 2),
        comment: '最低薪资'
    },
    max_salary: {
        type: DataTypes.DECIMAL(10, 2),
        comment: '最高薪资'
    },
    salary_unit: {
        type: DataTypes.STRING,
        comment: '薪资单位'
    },
    work_status: {
        type: DataTypes.INTEGER,
        comment: '0-待审核 1-审核通过 2-审核未通过 3-已招满'
    },
}, {
    timestamps: false
});

module.exports = { Work };
